package com.weather.controller;

import com.weather.service.CityDataService;
import com.weather.service.WeatherReportService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author: htc
 * @date: Created in 17:52 2018/5/4.
 */
@RequestMapping("/weather")
@RestController
public class WeatherReportController {
    @Resource
    private WeatherReportService reportService;

    @Resource
    private CityDataService cityDataService;

    @GetMapping("/cityName/{cityName}")
    public ModelAndView getReportByCityName(@PathVariable("cityName") String cityName, Model model) throws Exception {
        model.addAttribute("title", "HTC天气预报");
        model.addAttribute("cityName", cityName);
        model.addAttribute("cityList", cityDataService.listCity());
        model.addAttribute("report", reportService.getWeatherByCityName(cityName));
        //返回视图 与 模型
        return new ModelAndView("weather/report", "reportModel", model);
    }
}
